import nibabel
import numpy as np

from .main_tool import generate_one


def update(nii_path, save_root):
    try:
        data = nibabel.load(nii_path)
        data = data.get_fdata()
        data = np.array(data)
        start_label = 1
        end_label = np.max(data)
        generate_one(nii_path, start_label, end_label, save_root, file_format='nii.gz',
                     model_format='obj', Origin=(0, 0, 0), Spacing=(1, 1, 1),
                     smoothing_iterations=15, pass_band=0.001, feature_angle=120.0,
                     file_prefix='', class_names=None, remove_class=None)
        return True
    except Exception as e:
        return False
